<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>点击</button>
    <script>
        // 箭头函数中的this指向
        // 1.箭头函数本身（内部）不绑定this

        // let fn = () =>{
        //     console.log(this);
        // }
        // fn();//Window

        
        // 案例2
        // 2.箭头函数中的this的指向，是跟着外层作用域中的this指向走的
        var name = "window";

        function fn(){
            setTimeout(() =>{
                console.log(this.name);
            })
        }

        fn();//window

        fn.call({name:"Object"});//Object

        // 案例3
        let btn = document.querySelector("button");

        btn.onclick = function(){
            setTimeout(function(){
                console.log(this);//window,因为定时器中回调函数里面的this指向window
            },300)
        }

        btn.onclick = function(){
            setTimeout(() =>{
                console.log(this);//btn,this指向跟外层作用域走
            },300)
        }

        btn.onclick = function(){
            this.innerHTML = "被点击了";//btn
        }

        btn.onclick = () =>{
            this.innerHTML = "被点击了";//window
        }

        


    </script>
</body>
</html>